home *** CD-ROM | disk | FTP | other *** search
- Path: shell1.eznet.net!not-for-mail
- From: armstron@eznet.net (Jon Armstrong)
- Newsgroups: comp.sys.amiga.programmer,uiuc.class.cs110c,uiuc.class.cs223
- Subject: Re: How do I define my integers?
- Date: 15 Jan 1996 22:25:16 -0500
- Organization: E-Znet, Incorporated, Rochester, NY 14604 (716)-262-2485
- Message-ID: <4df5qs$sg6@shell1.eznet.net>
- References: <4d73ug$25v@vixen.cso.uiuc.edu>
- NNTP-Posting-Host: shell1.eznet.net
-
- In article <4d73ug$25v@vixen.cso.uiuc.edu>,
- howard daniel joseph <djhoward@ux5.cso.uiuc.edu> wrote:
-
- >How do I declare signed versus unsigned integers?
-
- int i; /* This is a signed integer */
- unsigned int u; /* This is an unsigned integer */
-
- >How do I know how many bits my integers are using?
-
- Look in <machine/limits.h>
-
- You will find defines for SHORTBITS, INTBITS, LONGBITS, etc.
- They use the sizeof() built-in feature of C.
-
- >How do I declare signed and unsigned long integers?
-
- long l;
- unsigned long ul;
-
- >What's with these "doubles" the book mysteriously alludes to?
-
- float f; /* This is a floating point number */
- double d; /* This is a double precision floating point number */
-
- These types allow the representation and manipulation of fractional
- (real) numbers, like 3.14159265, etc.
-
- >What *am* I creating when I type;
- >
- >int somevalue;
-
- It's a signed integer, which is sizeof(int) bytes in size. Normally
- 4 bytes or 32 bits on a current Amiga.
-
- #include <machine/limits.h>
-
- int main()
- {
- printf("INTBITS = %d\n",INTBITS);
- return 0;
- }
-
- Result:
-
- INTBITS = 32
-
- >An integer (unsigned) that can handle, 6, though ideally 9 places (Just
- >under 250000000 would be the maximum forseen possible value here.)
-
- printf("ULONG_MAX = %u\n",ULONG_MAX);
-
- ULONG_MAX = 4294967295
-
- >An integer that can handle a much bigger number ... 12 places at least for
- >now.
-
- You don't say signed or unsigned, so I'll assume unsigned.
-
- I don't believe there currently exists an elementary type to handle
- this case on the Amiga with GCC. You'd have to find a suitable
- library for this or write your own set of routines to handle a type
- like...
-
- typedef struct { unsigned long high; unsigned long low; } large_t;
-
- Alternatively, you might consider using a double, which is 8 bytes
- in size (mantissa/exponent/etc), but is a real, not an integer type.
-
- I believe the type .. long long .. or similar may be coming along in
- the near future, but it's not quite here, yet. You may find it on
- certain platforms with certain compilers.
-
- >Can I perform simple maths (addition, division) between integers of
- >different types? I'd assume so, right?
-
- Yes.
-
- --
- +----------------------------------------------+
- Regards... Jon | Armstrong | LPA Software, Inc. | jma@lpa.com |
- +----------------------------------------------+
-